package chapter_20_memento.classic_black_box;

/**
 * @author yaochenglong
 * @date 2017/10/24
 *
 * 发起人对象
 */
public class Originator {

    private String state="";

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public Memento createMemento(){
        return new Memento(this.state);
    }

    public void restoreState(IMemento iMemento){
        this.state = ((Memento)iMemento).getState();
    }

    //将备忘录类建在Originator内部，并且所有的访问修饰符为private，使得除了Originator之外的类不能访问
    private class Memento implements IMemento{

        private String state;

        private Memento(String state) {
            this.state = state;
        }

        private String getState() {
            return state;
        }

        private void setState(String state) {
            this.state = state;
        }
    }
}
